/**
 * 
 */
package com.dsteiner.xelavos.client;

import com.dsteiner.widgets.client.domain.Sort;
import com.dsteiner.widgets.client.event.EventManagerImpl;
import com.dsteiner.widgets.client.rpc.SearchRequest;
import com.dsteiner.xelavos.client.domain.SearchRequestXelavos;
import com.dsteiner.xelavos.client.event.SearchEvent;
import com.dsteiner.xelavos.client.event.TabSelectionEvent;
import com.dsteiner.xelavos.client.model.MainTabModel.Tab;
import com.dsteiner.xelavos.client.resources.XelavosResources;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.InlineHTML;

public class SearchLink extends InlineHTML{
	public SearchLink(final String text, final String searchText, final Tab tab, final Sort sort) {
		super("<a href=\"javascript:void(0);\">"+text+"</a>");
		addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				EventManagerImpl.getInstance().fireEvent(new TabSelectionEvent(tab));
				SearchRequestXelavos searchRequest = new SearchRequestXelavos();
				searchRequest.setType(SearchRequest.TYPE_PREFIX);
				searchRequest.setText(searchText);
				searchRequest.setClassName(tab.getClassName());
				searchRequest.setSort(sort);
				EventManagerImpl.getInstance().fireEvent(new SearchEvent(searchRequest));
			}
		});
		addStyleName(XelavosResources.INSTANCE.css().searchLink());
	}
	public SearchLink(final String text, final Tab tab, final Sort sort) {
		this(text, text, tab, sort);
	}
}